package com.prometheus.pushgateway;

import io.prometheus.client.CollectorRegistry;
import io.prometheus.client.Gauge;
import io.prometheus.client.exporter.PushGateway;

import java.io.IOException;

/**
 * @program: azkaban-java-api
 * @author: jzhou
 * @date: 2022-10-20 14:51
 * @version: 1.0
 * @description: 统计监控指标发往pushgateway
 **/
public class JobReport {
	public static void main(String[] args) throws IOException {
		CollectorRegistry registry = new CollectorRegistry();

		Gauge uidCounter = Gauge.build().name("uid_counter").labelNames("type").help("uid 数量").register(registry);
		uidCounter.labels("msisdn_count").set(106);
		uidCounter.labels("imei_count").set(103);
		uidCounter.labels("imsi_count").set(97);
		uidCounter.labels("all_count").set(94);
		uidCounter.labels("station_count").set(94);
		Gauge uidFillingRate = Gauge.build().name("uid_filling_rate").labelNames("type").help("uid 填充率").register(registry);
		uidFillingRate.labels("msisdn_filling_rate").set(0.64);
		uidFillingRate.labels("imei_filling_rate").set(0.63);
		uidFillingRate.labels("imsi_filling_rate").set(0.62);
		uidFillingRate.labels("all_filling_rate").set(0.62);
		uidFillingRate.labels("station_rate").set(0.62);

		Gauge fileUserCounter = Gauge.build().name("file_user_counter").labelNames("type").help("五大类文件中各个文件中用户数").register(registry);
		fileUserCounter.labels("ysb").set(0.64);
		fileUserCounter.labels("http").set(0.63);
		fileUserCounter.labels("https").set(0.62);
		fileUserCounter.labels("dns").set(0.62);
		fileUserCounter.labels("wzl").set(0.62);
//		Gauge imsiCount = Gauge.build().name("bash_counter").labelNames("type").help("解析 imei 数量").register(registry);
//		Gauge allCount = Gauge.build().name("bash_counter").labelNames("type").help("三码均有值数量").register(registry);

//		Gauge msisdnFillingRate = Gauge.build().name("msisdn_filling_rate").help("msisdn 解析率").register(registry);
//		Gauge imeiFillingRate = Gauge.build().name("imei_filling_rate").help("imei 解析率").register(registry);
//		Gauge imsiFillingRate = Gauge.build().name("imsi_filling_rate").help("imsi 解析率").register(registry);
//		Gauge allRate = Gauge.build().name("all_filling_rate").help("三码均有值 解析率").register(registry);

//		Gauge.Timer durationTimer = duration.startTimer();

//		try {
			// Your code here.

			// This is only added to the registry after success,
			// so that a previous success in the Pushgateway isn't overwritten on failure.
//			Gauge lastSuccess = Gauge.build().name("my_batch_job_last_success").help("Last time my batch job succeeded, in unixtime.")
//					.labelNames("jzhou")
//					.register(registry);
//			lastSuccess.setToCurrentTime();
//			lastSuccess.labels("bbb").set(456);
//		} finally {
//			durationTimer.setDuration();
			PushGateway pg = new PushGateway("172.16.128.95:9091");
			pg.pushAdd(registry, "flowai_data_quality");
//			pg.
//		}

//		PushGateway pg = new PushGateway(args[0]);
//		g.set(42);
//		pg.push(pushRegistry, "job");
	}
}
